package org.duoyi.striver.global;

import com.develop.jawin.COMException;
import org.duoyi.jdm.Dm.DmInstant;

public class DmManager {

    private static final ThreadLocal<DmInstant> dmLocal = new ThreadLocal<>();

    public static void put(DmInstant dmInstant) {
        dmLocal.set(dmInstant);
    }

    public static DmInstant get() {
        return dmLocal.get();
    }

    public static void clear() {
        DmInstant dmInstant = dmLocal.get();
        if (dmInstant != null) {
            try {
                dmInstant.UnBindWindow();
            } catch (COMException e) {
                // do nothing
            }
        }
        dmLocal.remove();
    }
}
